package com.serkol.ams.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.serkol.ams.bean.MyPage;
import com.serkol.ams.bean.MyPageOld;
import com.serkol.ams.entity.AgentRechangeLog;
import com.serkol.ams.mapper.AgentRechangeLogMapper;
import com.serkol.ams.service.AgentRechangeLogService;
import com.serkol.handler.MyLambdaQueryWrapper;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author pingan
 * @description 针对表【agent_rechange_log】的数据库操作Service实现
 * @createDate 2022-10-19 00:05:48
 */
@Service
public class AgentRechangeLogServiceImpl extends ServiceImpl<AgentRechangeLogMapper, AgentRechangeLog>
        implements AgentRechangeLogService {

    @Override
    public MyPage<Map<String, Object>> findByPageBackAgentReChangeList(int pageSize, int current, long userId) {
        MyLambdaQueryWrapper<AgentRechangeLog> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.authName(AgentRechangeLog::getUserId).as("name").authName(AgentRechangeLog::getOperatorId).as("operatorName").authName(AgentRechangeLog::getParentUserId).as("parentUserName").authName(AgentRechangeLog::getOldParentUserId).as("oldParentUserName");
        queryWrapper.agentName(AgentRechangeLog::getAgentId).as("agentName").agentName(AgentRechangeLog::getOldAgentId).as("oldAgentName");
        queryWrapper.select(AgentRechangeLog::getRemark, AgentRechangeLog::getCreateDate);
        queryWrapper.eq(AgentRechangeLog::getUserId, userId).orderByDesc(AgentRechangeLog::getCreateDate);

        Page<Map<String, Object>> page = new Page<>(current, pageSize);
        IPage<Map<String, Object>> data = this.baseMapper.selectMapsPage(page, queryWrapper);

        return MyPage.parsePage(data);
    }
}




